/// @tags:
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e6;

char str[maxn + 2];

int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> (str + 1);
    int n = strlen(str + 1);
    bool flag = false;
    for (int i = 2; i <= n; ++i) {
      if (str[i] != str[1]) {
        cout << n + n - i + 1 << '\n';
        flag = true;
        break;
      }
    }
    if (!flag) {
      cout << n - 1 << '\n';
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("L. Suzuran Loves String.in", "r", stdin);
  freopen("L. Suzuran Loves String.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
